﻿FlyTalk.views.SearchSearchView = Ext.extend(Ext.form.FormPanel, {
	title: 'Search',
	scroll: true,
        
    initComponent: function () {
        // back button on toolbar  

		this.backButton = new Ext.Button({
			
			iconCls: 'home',
			iconMask: true,
			handler: this.backButtonTap,
			scope: this
		});
		
		this.searchButton = new Ext.Button({
			iconCls: 'search',
			iconMask: true,
			handler: this.searchButtonTap,
			scope: this
		});
    	
    	
		this.toolbar = new Ext.Toolbar({
				title: 'Search/Ask',
				doc: 'top',
				layout: 'hbox',
				items: [
					this.backButton,
					{xtype: 'spacer'},
					this.searchButton,
				]
		});
		
		this.dockedItems = [this.toolbar];
		
		this.on('render', function () {
			this.items.getAt(1).hide();
			this.doComponentLayout(); 
		});
		
        FlyTalk.views.SearchSearchView.superclass.initComponent.call(this);
    },  
    
    items: [
        { // serach in
        xtype: 'textfield',
        name: 'search',
			id: 'searchfield',
        label: 'Search',
        required: true
        },
        {
        	xtype: 'panel',
        	id: 'resultsPanel',
        	hidden: true,
        	items: [
        	        {html:'<div style="font-size: small">Sorry, no results found. Would you like to try asking the community?</div>'},
        	        {
		        		xtype:'button',
		        		text: 'Ask the Community',
		        		style: 'margin: .5em',
		        		handler: function(){
		        			 FlyTalk.views.TalkView.tweetToolbar.setTitle('Search');
		        			 Ext.dispatch({
		        		            controller: FlyTalk.controllers.ftController,
		        		            action: 'openQuestion'
		        		     });
		        		}
		        	
        	        }
        	        ]
        }
	],
	
	backButtonTap: function () {
		this.items.getAt(1).hide();
    	this.doComponentLayout(); 
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openHome'
        });
    },
    
  
    searchButtonTap: function () {
    	//alert("in search");
    	//this.items.getAt(1).hide();
    	
    	//this.items.getAt(1).setVisible(true);
    	this.items.getAt(1).show();
    	this.doComponentLayout(); 
    	//this.items.getAt(1).hidden = false;
    	//this.update();
    },

});
